import java.io.IOException;

import org.kwis.msp.lcdui.Jlet;
import org.kwis.msp.lcdui.Display;
import org.kwis.msp.lcdui.Card;
import org.kwis.msp.lcdui.Image;

import org.kwis.msp.lwc.Component;
import org.kwis.msp.lwc.ShellComponent;
import org.kwis.msp.lwc.ListComponent;
import org.kwis.msp.lwc.ListItemComponent;
import org.kwis.msp.lwc.LabelComponent;
import org.kwis.msp.lwc.ActionListener;
import org.kwis.msp.lwc.ButtonComponent;

public class ListComponentEx3 extends Jlet{

	
	public class ActionListenerHandler implements ActionListener{
				
		ButtonComponent backButton;
		Image backArrow = null;

		public void action(Component cmp , Object obj){
			
			if(cmp==list){

				displayLCD.popCard();
				ShellComponent actionShell = new ShellComponent();
				ListComponent subList = new ListComponent(ListComponent.SELECT_EXCLUSIVE);
				ListItemComponent subItem1 = new ListItemComponent("심슨   123-4567");
				ListItemComponent subItem2 = new ListItemComponent("릴라   123-4567");
				ListItemComponent subItem3 = new ListItemComponent("제니   123-4567");

				subList.addComponent(subItem1);
				subList.addComponent(subItem2);
				subList.addComponent(subItem3);
				
				actionShell.setWorkComponent(subList);

				try{
					backArrow = Image.createImage("/backArrow.gif");
				}catch(IOException e){
					System.out.println(e);
				}

				backButton = new ButtonComponent("되돌아 가기" , backArrow);
				backButton.setActionListener(this,null);
				actionShell.setCommand(backButton,true);

				displayLCD.pushCard(actionShell.getCard());
				//actionShell.show();
							
			}
			else if(cmp==backButton){
				displayLCD.popCard();
				displayLCD.pushCard(menuCard);
			
			}

		}
	}



	Display displayLCD ;
	ShellComponent shell;
	ListComponent list;
	Card menuCard;

	public ListComponentEx3(){      }

	protected void startApp(String[] arg0){

		
		displayLCD = Display.getDefaultDisplay();
		shell = new ShellComponent();

		list = new ListComponent(ListComponent.SELECT_IMPLICIT);
		ListItemComponent item1 = new ListItemComponent("전화번호부");
		ListItemComponent item2 = new ListItemComponent("개인일정관리");
		ListItemComponent item3 = new ListItemComponent("부가기능");
		ListItemComponent item4 = new ListItemComponent("게임");

		list.addComponent(item1);
		list.addComponent(item2);
		list.addComponent(item3);
		list.addComponent(item4);

		list.setActionListener(new ActionListenerHandler(),null);


		LabelComponent lbListTitle = new LabelComponent("  Main Menu List");

		shell.setTitle(lbListTitle);
		shell.setWorkComponent(list);

		menuCard = shell.getCard();

		displayLCD.pushCard(menuCard);
		
	}
	protected void destroyApp(boolean arg0) {  }

	

}
